﻿<template>
     <el-dialog :close-on-click-modal="false"  :close-on-press-escape="false"  title="编辑" :append-to-body="true" :visible="modalEdit" @close="modalEdit=false"  @opened="opened" @closed="closed" >
        <el-form ref="sysRole" label-position="left" label-width="120px" :model="sysRole" :rules="rules">
            <input type="hidden" :model="sysRole.id" />
            <el-form-item label="角色" prop="roleName">
                <el-input size="small" v-model="sysRole.roleName" placeholder="角色" style="width: 240px" />
            </el-form-item>
          
            <el-form-item label="状态" prop="state">
            
                <el-radio-group  size="small" v-model="sysRole.state">
                    <el-radio :label="1">启用</el-radio>
                    <el-radio :label="0">禁用</el-radio>
                </el-radio-group>
            </el-form-item>

            </el-form-item>
        </el-form>
        <div slot="footer">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" :loading="modalLoading" @click="ok">确定</el-button>
        </div>
    </el-dialog>
    
</template>
<script>
export default {
    name: 'SysRole',
    data() {
        return {

            modalEdit: false,
            modalLoading: false,
            sysRoleId: "",
            sysRole: {
                state:1
            },
            rules: {
                state:[
                {required:true,message:"不能为空"}
                ],
                 roleName:[
                {required:true,message:"角色不能为空"}
                ]
            }
        };
    },
    mounted: function() {
       

    },
    methods: {
        
        opened() {

            this.getDetail();

        },
        closed: function() {
            this.sysRole = {
                state:1
            }
        },
        showDialog(id) {
            this.sysRoleId = id;
            this.modalEdit = true;
        },
        getDetail: function() {
            if (this.sysRoleId == null || this.sysRoleId == undefined || this.sysRoleId == "") return;
            var me = this;
            me.showLoading();
            me.$http.post("/sys/sysrole/show_" + me.sysRoleId + ".action").then(response => {
                var body = response;
                if (body.status == 0) {
                    me.sysRole = body.obj;

                }
                me.hideLoading();
            }, response => {
                me.hideLoading();
            });
        },
        ok: function() {
            var ok = false;
            this.$refs['sysRole'].validate((valid) => {
                ok = valid;
                if (valid) {

                } else {
                    this.errorMessage('请认真填写数据');
                }
            })
            if (!ok) return;
            var me = this;
            me.modalLoading = true;
            me.$http.post("/sys/sysrole/doSave.action", me.sysRole).then(response => {
                var body = response;
                if (body.status == 0) {
                    me.successMessage("保存成功！");
                    me.modalEdit = false;
                    me.$emit("ok");

                } else {
                    me.errorMessage(body.info);
                }
                me.modalLoading = false;
            }, response => {
                me.modalLoading = false;
            });
        },
        cancel: function() {
            this.sysRole = {};
            this.modalEdit = false;
            this.$emit("ok");
        }
    }
}
</script>
<style scoped>
</style>